package dev.tools.view.panels;

import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;

/**
 * User: Nuno Date: 25-05-2013 Time: 17:53
 */
public class HtmlPanel extends JScrollPane {

    /**
     *
     */
    private static final long serialVersionUID = -633314643497137693L;

    public HtmlPanel(final String code) {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {

                // create jEditorPane
                final JEditorPane editorPane = new JEditorPane();

                // make it read-only
                editorPane.setEditable(false);

                setViewportView(editorPane);

                // add an html editor kit
                final HTMLEditorKit kit = new HTMLEditorKit();
                editorPane.setEditorKit(kit);

                // create a document, set it on the jEditorPane, then add the
                // html
                editorPane.setDocument(kit.createDefaultDocument());
                editorPane.setText(code);
            }
        });
    }
}
